﻿using System.Collections.Generic;
using Assets.Scripts.Net.Data;
using Assets.Scripts.Net.Data.Model;
using Assets.Scripts.UI.Item;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.UI.Panel
{
    public class HomeWorkPanel : UIBase<HomeWorkPanel>
    {
        public Button ExitButton;
        public Button SettingButton;
        public Transform Content_Course;//课程
        public Transform Content_Finish;//已完成作业 
        public Transform Content_UnFinish;//未完成

        public static HomeWorkPanel _Instance;

        public static CourseItem NowClickCourseItem { get; set; }//存储当前点击的课程item
     
        protected override UIType UIType
        {
            get { return UIType.Panel;}
        }

        protected override void InitOnAwake()
        {
            _Instance = this;
            AutoFindComponent(transform,true);
            ExitButton.onClick.AddListener(Exit);
            SettingButton.onClick.AddListener(() => { CreatePanel(PanelType.SettingPanel); });
        }

        /// <summary>
        /// 初始化家庭作业的信息
        /// </summary>
        /// <param name="infos"></param>
        public void Init(List<CourseInfo> infos)
        {
            //Debug.Log("courseinfo.count:"+infos.Count);
            for (int i = 0; i < infos.Count; i++)
            {
                Transform tsf = CreateItem(ItemType.CourseItem);
                tsf.SetParent(Content_Course);
                tsf.localPosition = Vector3.zero;
                tsf.localScale = Vector3.one;
                CourseItem item = tsf.GetComponent<CourseItem>();
                item.Init(infos[i], NetConstValue.HW_CourseInfo, new[] {Content_Finish, Content_UnFinish});
                if(i==0)item.CourseButton.onClick.Invoke();//默认调用第一个
            }  
        }

        protected override void InitOnDestroy()
        {
            NowClickCourseItem = null;
            _Instance = null;
        }
    }
}
